package com.zjdiepu.www.manage.api.base;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.zjdiepu.www.base.BaseController;
import com.zjdiepu.www.base.core.ApiResponse;
import com.zjdiepu.www.base.core.PageVo;
import com.zjdiepu.www.base.enums.type.OperateType;
import com.zjdiepu.www.common.util.CollectionInitUtil;
import com.zjdiepu.www.commpent.mapper.base.DpBaseContractVersionVoMapper;
import com.zjdiepu.www.ibiz.base.IDpBaseContractVersionService;
import com.zjdiepu.www.model.base.dto.DpBaseContractVersion;
import com.zjdiepu.www.model.base.ext.DpBaseContractVersionExt;

/**
 * 所属公司：稻普控股集团
 * 项目名称：dpqc-parent-manager-home
 * 类名称：ContractVersionController
 * 类描述：
 * 创建人：winby
 * 创建时间：2017年4月5日15:57:49
 * 修改人：winby
 * 修改时间：2017年4月5日15:57:49
 * 修改备注：
 *
 * @version V1.0
 */
@RestController
@RequestMapping("/ContractVersionController")
@Api(value = "ContractVersionController", tags = "合同版本")
public class ContractVersionController extends BaseController {
    protected static final String CONTROLLER_NAME = "合同版本";
    @Resource
    private IDpBaseContractVersionService iDpBaseContractVersionService;
    @Resource
    private DpBaseContractVersionVoMapper dpBaseContractVersionVoMapper;

    /**
     * @author winby
     * @Title: save
     * @Description: 新增
     * @param entity
     * @return
     * @version V1.0
     */
    @ApiOperation(value = "新增", response = DpBaseContractVersion.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", paramType = "query", dataType = "String", required = false, defaultValue = ""),
            @ApiImplicitParam(name = "dataDictionaryValue", value = "数据字典(银行)", paramType = "query", dataType = "String", required = false, defaultValue = "123"),
            @ApiImplicitParam(name = "contractVersion", value = "合同版本号", paramType = "query", dataType = "String", required = false, defaultValue = "123")
    })
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public ApiResponse save(DpBaseContractVersion entity) {
        iDpBaseContractVersionService.saveUpdateAndDelete(entity, OperateType.add);
        return ApiResponse.success(true);
    }

    /**
     * @author winby
     * @Title: remove
     * @Description: 删除
     * @param entity
     * @return
     * @version V1.0
     */
    @ApiOperation(value = "删除", response = DpBaseContractVersion.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", paramType = "query", dataType = "String", required = false, defaultValue = ""),
            @ApiImplicitParam(name = "dataDictionaryValue", value = "数据字典(银行)", paramType = "query", dataType = "String", required = false, defaultValue = "123"),
            @ApiImplicitParam(name = "contractVersion", value = "合同版本号", paramType = "query", dataType = "String", required = false, defaultValue = "123")
    })
    @RequestMapping(value = "/remove", method = RequestMethod.POST)
    public ApiResponse remove(DpBaseContractVersion entity) {
        iDpBaseContractVersionService.saveUpdateAndDelete(entity, OperateType.delete);
        return ApiResponse.success(true);
    }

    /**
     * @author winby
     * @Title: modify
     * @Description: 修改
     * @param entity
     * @return
     * @version V1.0
     */
    @ApiOperation(value = "修改", response = DpBaseContractVersion.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", paramType = "query", dataType = "String", required = false, defaultValue = ""),
            @ApiImplicitParam(name = "dataDictionaryValue", value = "数据字典(银行)", paramType = "query", dataType = "String", required = false, defaultValue = "123"),
            @ApiImplicitParam(name = "contractVersion", value = "合同版本号", paramType = "query", dataType = "String", required = false, defaultValue = "123")
    })
    @RequestMapping(value = "/modify", method = RequestMethod.POST)
    public ApiResponse modify(DpBaseContractVersion entity) throws Exception {
        iDpBaseContractVersionService.saveUpdateAndDelete(entity, OperateType.edit);
        return ApiResponse.success(true);
    }

    /**
     * @author winby
     * @Title: getById
     * @Description: ID查询
     * @param id
     * @return
     * @version V1.0
     */
    @ApiOperation(value = "ID查询", response = DpBaseContractVersion.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", paramType = "query", dataType = "String", required = false, defaultValue = "")
    })
    @RequestMapping(value = "/getById", method = RequestMethod.POST)
    public ApiResponse getById(String id) throws Exception {
        DpBaseContractVersion result = iDpBaseContractVersionService.selectById(id);
        return ApiResponse.success(result);
    }

    /**
     * @author winby
     * @Title: list
     * @Description: 条件查询
     * @param entity
     * @return
     * @version V1.0
     */
    @ApiOperation(value = "条件查询", response = DpBaseContractVersion.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", paramType = "query", dataType = "String", required = false, defaultValue = ""),
            @ApiImplicitParam(name = "dataDictionaryValue", value = "数据字典(银行)", paramType = "query", dataType = "String", required = false, defaultValue = "123"),
            @ApiImplicitParam(name = "contractVersion", value = "合同版本号", paramType = "query", dataType = "String", required = false, defaultValue = "123")
    })
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public ApiResponse list(DpBaseContractVersionExt entity) throws Exception {
        entity.notDeleted();
        PageVo page = getPage(entity);
        int records = iDpBaseContractVersionService.countByExt(entity);
        page.setRecords(records);
        if (records > 0) {
            List<DpBaseContractVersion> dpBaseDataDictionaries = iDpBaseContractVersionService.selectByExt(entity);
            dpBaseContractVersionVoMapper.mapper(dpBaseDataDictionaries);
            page.setRows(dpBaseDataDictionaries);
        } else {
            page.setRows(CollectionInitUtil.emptyList());
        }
        return ApiResponse.success(page);
    }

}
